/*
 * Packet.h
 *
 *  Created on: 26.10.2012
 *      Author: Sven
 */

#ifndef PACKET_H_
#define PACKET_H_

/* PACKET TYPES */
#define PACKET_AUTH			0
#define PACKET_KEEPALIVE	1
#define PACKET_LOGOUT		2
#define PACKET_STRING		3
#define PACKET_MAPDATA		4
#define PACKET_OBJECT		5

/* PACKET */
typedef struct
{
	unsigned short	size;
	unsigned char	type;
	unsigned char	data[];
} BASE_PACKET;

class CPacket
{
public:
	CPacket(BASE_PACKET* packet, CSession* session);
	CPacket(unsigned char type, short size, CSession* session);
	~CPacket();

	BASE_PACKET*	getpacket() { return m_packet; }
	CSession*		getsession() { return m_session; }

	void			setbyte(int index, unsigned char data);
	void			setdata(int index, int data);
	void			setranddata(int index);
	void			appenddata(int index, char* buffer, int size);

	void			handle();

	static void		push(CPacket* packet);
	static CPacket*	pull();

	static queue<CPacket*>	m_rcvqueue;
	static queue<CPacket*>	m_sendqueue;
private:
	BASE_PACKET*			m_packet;
	CSession*				m_session;

	int						m_size;
};


#endif /* PACKET_H_ */
